# -*- coding: utf-8 -*-
# created on 2016/9/28

from mathsolver.functions.base import *
from sympy import acos, pi, sqrt


# 求两条切线所夹的圆心角
class AngleOfTangentLines(BaseFunction):
    def solver(self, *args):
        yuanxin_todian_juli = args[0].sympify()
        banjing = args[1].sympify()
        angle = 2 * acos(banjing / yuanxin_todian_juli)
        self.output.append(BaseNumber(angle))
        self.steps.append(["", "∴两条切线所成的夹角为%s" % (new_latex(angle))])
        self.label.add("求两条切线所夹的圆心角")
        return self


# 求两条切线所夹的劣弧长
class LengthOfMinorArc(BaseFunction):
    def solver(self, *args):
        angle = args[0].sympify()
        banjing = args[0].sympify()
        l1 = angle * banjing
        l2 = 2 * pi - l1
        ll = min(l1, l2)
        self.steps.append(["", "由弧长公式知，劣弧长为%s" % (new_latex(ll))])
        self.output.append(BaseNumber(ll))
        self.label.add("求两条切线所夹的劣弧长")
        return self


# 求两条切线所夹的优弧长
class LengthOfMajorArc(BaseFunction):
    def solver(self, *args):
        angle = args[0].sympify()
        banjing = args[0].sympify()
        l1 = angle * banjing
        l2 = 2 * pi - l1
        ll = max(l1, l2)
        self.steps.append(["", "由弧长公式知，优弧长为%s" % (new_latex(ll))])
        self.output.append(BaseNumber(ll))
        self.label.add("求两条切线所夹的优弧长")
        return self


# 求直线截圆劣弧所对的圆心角
class LineToAngle(BaseFunction):
    def solver(self, *args):
        yuanxin_to_line_juli = args[0].sympify()
        banjing = args[1].sympify()
        angle = 2 * acos(yuanxin_to_line_juli / banjing)
        self.steps.append(["", "∴直线截圆劣弧所对的圆心角为%s" % (new_latex(angle))])
        self.label.add("求直线截圆劣弧所对的圆心角")
        self.output.append(BaseNumber(angle))
        return self


# 求直线截圆所得的劣弧长
class LineToMajorArc(BaseFunction):
    def solver(self, *args):
        angle = args[0].sympify()
        banjing = args[1].sympify()
        ll = angle * banjing
        self.steps.append(["", "∴直线截圆所得的弧长为%s" % (new_latex(ll))])
        self.label.add("求直线截圆所得的弧长")
        self.output.append(BaseNumber(ll))
        return self


# 切线长度
class TangentOfLength(BaseFunction):
    """
    过点(4,4)引圆(x-1)^{2}+(y-3)^{2}=4的切线,则切线长是()
    """
    def solver(self, *args):
        yuanxinju = args[0].sympify()
        banjing = args[1].sympify()
        qiexianchang = sqrt(yuanxinju ** 2 - banjing ** 2)
        self.steps.append(["", "∴切线长度为%s" % (new_latex(qiexianchang))])
        self.output.append(BaseNumber(qiexianchang))
        return self
